1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module soup.MultipartInputStream;
26 
27 private import gio.AsyncResultIF;
28 private import gio.Cancellable;
29 private import gio.FilterInputStream;
30 private import gio.InputStream;
31 private import gio.PollableInputStreamIF;
32 private import gio.PollableInputStreamT;
33 private import glib.ConstructionException;
34 private import glib.ErrorG;
35 private import glib.GException;
36 private import gobject.ObjectG;
37 private import soup.Message;
38 private import soup.MessageHeaders;
39 private import soup.c.functions;
40 public  import soup.c.types;
41 
42 
43 /** */
44 public class MultipartInputStream : FilterInputStream, PollableInputStreamIF
45 {
46 	/** the main Gtk struct */
47 	protected SoupMultipartInputStream* soupMultipartInputStream;
48 
49 	/** Get the main Gtk struct */
50 	public SoupMultipartInputStream* getMultipartInputStreamStruct(bool transferOwnership = false)
51 	{
52 		if (transferOwnership)
53 			ownedRef = false;
54 		return soupMultipartInputStream;
55 	}
56 
57 	/** the main Gtk struct as a void* */
58 	protected override void* getStruct()
59 	{
60 		return cast(void*)soupMultipartInputStream;
61 	}
62 
63 	/**
64 	 * Sets our main struct and passes it to the parent class.
65 	 */
66 	public this (SoupMultipartInputStream* soupMultipartInputStream, bool ownedRef = false)
67 	{
68 		this.soupMultipartInputStream = soupMultipartInputStream;
69 		super(cast(GFilterInputStream*)soupMultipartInputStream, ownedRef);
70 	}
71 
72 	// add the PollableInputStream capabilities
73 	mixin PollableInputStreamT!(SoupMultipartInputStream);
74 
75 
76 	/** */
77 	public static GType getType()
78 	{
79 		return soup_multipart_input_stream_get_type();
80 	}
81 
82 	/**
83 	 * Creates a new #SoupMultipartInputStream that wraps the
84 	 * #GInputStream obtained by sending the #SoupRequest. Reads should
85 	 * not be done directly through this object, use the input streams
86 	 * returned by soup_multipart_input_stream_next_part() or its async
87 	 * counterpart instead.
88 	 *
89 	 * Params:
90 	 *     msg = the #SoupMessage the response is related to.
91 	 *     baseStream = the #GInputStream returned by sending the request.
92 	 *
93 	 * Returns: a new #SoupMultipartInputStream
94 	 *
95 	 * Since: 2.40
96 	 *
97 	 * Throws: ConstructionException GTK+ fails to create the object.
98 	 */
99 	public this(Message msg, InputStream baseStream)
100 	{
101 		auto __p = soup_multipart_input_stream_new((msg is null) ? null : msg.getMessageStruct(), (baseStream is null) ? null : baseStream.getInputStreamStruct());
102 
103 		if(__p is null)
104 		{
105 			throw new ConstructionException("null returned by new");
106 		}
107 
108 		this(cast(SoupMultipartInputStream*) __p, true);
109 	}
110 
111 	/**
112 	 * Obtains the headers for the part currently being processed. Note
113 	 * that the #SoupMessageHeaders that are returned are owned by the
114 	 * #SoupMultipartInputStream and will be replaced when a call is made
115 	 * to soup_multipart_input_stream_next_part() or its async
116 	 * counterpart, so if keeping the headers is required, a copy must be
117 	 * made.
118 	 *
119 	 * Note that if a part had no headers at all an empty #SoupMessageHeaders
120 	 * will be returned.
121 	 *
122 	 * Returns: a #SoupMessageHeaders
123 	 *     containing the headers for the part currently being processed or
124 	 *     %NULL if the headers failed to parse.
125 	 *
126 	 * Since: 2.40
127 	 */
128 	public MessageHeaders getHeaders()
129 	{
130 		auto __p = soup_multipart_input_stream_get_headers(soupMultipartInputStream);
131 
132 		if(__p is null)
133 		{
134 			return null;
135 		}
136 
137 		return ObjectG.getDObject!(MessageHeaders)(cast(SoupMessageHeaders*) __p);
138 	}
139 
140 	/**
141 	 * Obtains an input stream for the next part. When dealing with a
142 	 * multipart response the input stream needs to be wrapped in a
143 	 * #SoupMultipartInputStream and this function or its async
144 	 * counterpart need to be called to obtain the first part for
145 	 * reading.
146 	 *
147 	 * After calling this function,
148 	 * soup_multipart_input_stream_get_headers() can be used to obtain the
149 	 * headers for the first part. A read of 0 bytes indicates the end of
150 	 * the part; a new call to this function should be done at that point,
151 	 * to obtain the next part.
152 	 *
153 	 * Params:
154 	 *     cancellable = a #GCancellable
155 	 *
156 	 * Returns: a new #GInputStream, or
157 	 *     %NULL if there are no more parts
158 	 *
159 	 * Since: 2.40
160 	 *
161 	 * Throws: GException on failure.
162 	 */
163 	public InputStream nextPart(Cancellable cancellable)
164 	{
165 		GError* err = null;
166 
167 		auto __p = soup_multipart_input_stream_next_part(soupMultipartInputStream, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
168 
169 		if (err !is null)
170 		{
171 			throw new GException( new ErrorG(err) );
172 		}
173 
174 		if(__p is null)
175 		{
176 			return null;
177 		}
178 
179 		return ObjectG.getDObject!(InputStream)(cast(GInputStream*) __p, true);
180 	}
181 
182 	/**
183 	 * Obtains a #GInputStream for the next request. See
184 	 * soup_multipart_input_stream_next_part() for details on the
185 	 * workflow.
186 	 *
187 	 * Params:
188 	 *     ioPriority = the I/O priority for the request.
189 	 *     cancellable = a #GCancellable.
190 	 *     callback = callback to call when request is satisfied.
191 	 *     data = data for @callback
192 	 *
193 	 * Since: 2.40
194 	 */
195 	public void nextPartAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* data)
196 	{
197 		soup_multipart_input_stream_next_part_async(soupMultipartInputStream, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, data);
198 	}
199 
200 	/**
201 	 * Finishes an asynchronous request for the next part.
202 	 *
203 	 * Params:
204 	 *     result = a #GAsyncResult.
205 	 *
206 	 * Returns: a newly created
207 	 *     #GInputStream for reading the next part or %NULL if there are no
208 	 *     more parts.
209 	 *
210 	 * Since: 2.40
211 	 *
212 	 * Throws: GException on failure.
213 	 */
214 	public InputStream nextPartFinish(AsyncResultIF result)
215 	{
216 		GError* err = null;
217 
218 		auto __p = soup_multipart_input_stream_next_part_finish(soupMultipartInputStream, (result is null) ? null : result.getAsyncResultStruct(), &err);
219 
220 		if (err !is null)
221 		{
222 			throw new GException( new ErrorG(err) );
223 		}
224 
225 		if(__p is null)
226 		{
227 			return null;
228 		}
229 
230 		return ObjectG.getDObject!(InputStream)(cast(GInputStream*) __p, true);
231 	}
232 }